﻿using Model.Result.Admin;

namespace Service.Base
{
    public class AuthSupportService : BaseService<TPermission>, IAuthSupportService
    {
        public AuthSupportService(IUnitOfWorkService se) : base(se)
        {
        }

        public bool CheckPower4CurrentAdmin(string powerCode)
        {
            if (_Redis.CheckKey("en", _CurrentAdmin.Token, Model.Enums.Common.Enum_RedisKey.AdminPowers))
            {
                var datas = _Redis.GetRedisAttr<List<RM_AdminPermissions>>("en", _CurrentAdmin.Token, Model.Enums.Common.Enum_RedisKey.AdminPowers);
                return datas.Any(o => o.PermissionId == powerCode);
            }
            return false;
        }

        public bool CheckToken4CustomerAdmin()
        {
            if (_CurrentAdmin != null)
            {
                return _Redis.CheckKey("en", _CurrentAdmin.Token, Model.Enums.Common.Enum_RedisKey.AdminToken);
            }

            return false;
        }

        public bool CheckToken4CustomerUser()
        {
            if (_CurrentCustomer != null)
            {
                return _Redis.CheckKey("en", _CurrentCustomer.Token, Model.Enums.Common.Enum_RedisKey.CustomerToken);
            }
            return false;
        }

        public bool CheckBind4CustomerUser()
        {
            if (_CurrentCustomer.Id != 0)
            {
                return _Redis.CheckKey("en", _CurrentCustomer.Token, Model.Enums.Common.Enum_RedisKey.CustomerToken);
            }
            return false;
        }
    }
}